﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace WeifenLuoWinFormDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            TestForm();
        }


        private void TestForm()
        {
            // 初始化DockPanel
            DockPanel panel = new DockPanel();

            // 创建一个新的DockContent实例
            DockContent content = new DockContent();
            content.Text = "示例窗口";

            // 将DockContent添加到DockPanel中，并设置停靠位置
            //panel.AddContent(content, DockState.DockLeft);
            
        }

        private void dockPanel1_ActiveContentChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            System.Threading.Thread.Sleep(100);

            BaseFrm frm1 = new NavFrm();
            BaseFrm frm2 = new UserFrm();
            BaseFrm frm3 = new SysFunFrm();

            OpenFrm(frm2);
            OpenFrm(frm3);

            OpenFrm(frm1, DockStyle.Left);
                        
            frm1.Activate();

        }


        private void OpenFrm(BaseFrm frm, DockStyle style)
        {
            frm.Show(this.dockPanel1);
            frm.DockTo(this.dockPanel1, style);
        }
        private void OpenFrm(BaseFrm frm)
        {
            frm.Show(this.dockPanel1);
        }



        //public DockContent ShowContent(string caption, Type formType, DockPanel _dockPanel)
        //{
        //    DockContent frm = FindDocument(caption);
        //    if (frm == null)
        //    {
        //        frm = ChildWinManagement.LoadMdiForm(Portal.gc.MainDialog, formType) as DockContent;
        //    }

        //    frm.Show(_dockPanel);
        //    frm.BringToFront();
        //    return frm;
        //}


        private DockContent FindDocument(string text, DockPanel _dockPanel)
        {
            if (_dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                foreach (Form form in MdiChildren)
                {
                    if (form.Text == text)
                    {
                        return form as DockContent;
                    }
                }

                return null;
            }
            else
            {
                foreach (DockContent content in _dockPanel.Documents)
                {
                    if (content.DockHandler.TabText == text)
                    {
                        return content;
                    }
                }

                return null;
            }
        }


        public void CloseAllDocuments(DockPanel _dockPanel)
        {
            if (_dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                foreach (Form form in MdiChildren)
                {
                    form.Close();
                }
            }
            else
            {
                IDockContent[] documents = _dockPanel.DocumentsToArray();
                foreach (IDockContent content in documents)
                {
                    content.DockHandler.Close();
                }
            }
        }
    }
}
